<template>
<view>
<!-- pages/index/listQuery/result/result.wxml -->
<view class="result" v-if="results">
  <view class="result-title">
    <image src="/static/images/sys/duanline.png" class="line"></image>
    <text class="title-text">查询结果：</text>
  </view>
  <view class="result-list">
    <view v-for="(item, index) in results" :key="index" class="result-item" v-if="item.show">
      <view v-for="(item, index2) in item" :key="index2" class="attr-list" v-if="index !== 'show'">
        <view class="name">{{index}}</view>
        <view class="desc">{{item}}</view>
      </view>
    </view>
  </view>
</view>
<view class="null-box" v-else>
  <image src="http://imgbdb3.bendibao.com/xcxbdb/file/20212/9/20210209162952_68962.png" mode="widthFix" class="fail-img"></image>
  <view class="fail-msg">未查询到相关信息</view>
  <navigator open-type="navigateBack" hover-class="btn">
    <button class="back">返回上一步</button>
  </navigator>
</view>
</view>
</template>

<script>
// pages/index/listQuery/result/result.js
const app = getApp();
const util = require("../../../../utils/util.js");
let attrList;
let toggleCollection = true;

export default {
  data() {
    return {
      results: [],
      scroll: false
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    // util.colleation(this, "名单查询");
    toggleCollection = true;
    attrList = JSON.parse(options.attr);
    util.getUrl(app.globalData.url).then(res => {
      let $getSelectResult = {
        ac: 'attr',
        model_id: options.modelId,
        data: JSON.stringify(attrList)
      };
      let apiUrl = 'listQuery.php';

      if (options.modelId === '1') {
        apiUrl = 'yaohao.php';
        $getSelectResult.ac = 'yaohao';
        $getSelectResult['city'] = options.cityName;
        delete $getSelectResult.model_id;
      } else if (options.modelId === '2') {
        $getSelectResult.ac = 'fangjia';
        $getSelectResult['city'] = options.cityName;
      }

      util.bstrequest(`${apiUrl}`, $getSelectResult, 'POST').then(res => {
        let results = JSON.parse(JSON.stringify(res.data.data));
        if (Array.isArray(results)) results = '';else for (let attrId in results) {
          for (let attr in results[attrId]) {
            if (results[attrId][attr]) results[attrId]['show'] = true;else results[attrId]['show'] = false;
          }
        }
        this.setData({
          results: results
        });
      });
    });
  },
  methods: {
    backBtn: function () {
      uni.navigateBack({});
    },

    onPageScroll() {
      if (toggleCollection) {
        this.setData({
          scroll: true
        });
        toggleCollection = false;
      }
    },

    closeCollection() {
      toggleCollection = false;
    },

    openCollection() {
      toggleCollection = true;
    }

  }
};
</script>
<style>
/* pages/index/listQuery/result/result.wxss */

page {
    padding-top: 32rpx;
    background-color: #f7f7f7;
    font-size: 28rpx;
  }
  
  .line {
    width: 8rpx;
    height: 32rpx;
    margin-right: 20rpx;
  }
  
  .result-title {
    display: flex;
    align-items: center;
    margin-left: 40rpx;
  }
  
  .title-text {
    font-size: 28rpx;
  }
  
  .result-list {
    margin: 34rpx 40rpx;
  }
  
  .result-item {
    background-color: #fff;
    margin-top: 20rpx;
    padding: 26rpx 40rpx;
  }
  
  .attr-list {
    display: flex;
    align-items: center;
    margin-top: 10rpx;
  }
  
  .attr-list:first-child {
    margin-top: 0;
  }
  
  .name {
    min-width: 30%;
    color: #000;
  }
  
  .desc {
    max-width: 70%;
    color: #7e7e7e;
  }
  
  .fail-img {
    height: 306rpx;
    width: 321rpx;
    margin-top: 20rpx;
    text-align: center;
  }
  
  .fail-msg {
    font-size: 28rpx;
    color: #8E8E8E;
  }
  
  .null-box {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    margin-top: 122rpx;
  }
  .back {
    width: 348rpx;
    margin-top: 108rpx;
    color: white;
    font-size: 28rpx;
    border-radius: 0;
    background: linear-gradient(to right, #FFAA00, #FF6600)
  }
</style>